<template>
  <div>
    <TopFilter ref="formpanel" :list="formList" :cols="4" :rows="2" labelWidth="70" :collapse="false" @filterChange="changeHandle"></TopFilter>
    <!-- @formChange="formchangeFun" -->
    <!-- :isSubmitBtn="true" -->

    <FilterTable
      ref="table"
      :columns="columnsR1"
      :isColumnFilter="false"
      columnsRef="PartTable"
      :isToperInfo="false"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'rows'"
      height="300"
      :onSyncTableData="changetablelist"
      :onRowSelectChange="columns => (this.selColumn = columns)"
      :onColumnsChange="columns => (this.columnsR1 = columns)"
    >
      <template slot="controls">
        <el-button size="small" type="primary" icon="el-icon-plus" @click="addHandle">新增</el-button>
        <el-button size="small" type="primary" @click="relatedItems">取消</el-button>
        <el-button size="small" type="primary" @click="downloadTemplate">导入模板下载</el-button>
        <el-button size="small" type="primary" @click="importPrice">导入</el-button>
      </template>
    </FilterTable>

    <Drawer
      ref="tablesingleCopy"
      :visible.sync="feedbackVisible"
      :title="dialogTitle"
      destroyOnClose
      :width="980"
      :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }"
    >
      <feedback :rowData="formData" :type.sync="this.type" @close="closeHandler" @changedata="changedata" />
    </Drawer>
    <!-- <Drawer
      :visible.sync="visibleDrawer"
      title="通知通告查看"
      :width="920"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
       >
      <info-modal v-model="initData" @close="infoClose" />
    </Drawer>-->
  </div>
</template>
<script>
import { dictionary } from '@/utils/dictMixin';
import { getMainList, deleteFeedback, searchFaultLocation, searchFaultType } from '@/api/repair/quaback/index';
import { findProjectModelList } from '@/api/repair/repair/labourManager'; // 车系
import feedback from './detail';
export default {
  components: {
    feedback
  },
  mixins: [dictionary],
  data() {
    this.conf = { add: '新增', edit: '编辑', sure: '确定' };
    this.type = '';
    return {
      formList: this.createFrom(),
      columnsR1: this.createTableColumns(),
      fetchApi: getMainList,
      fetchParams: {},
      formData: {},
      selectArray: [],
      feedbackVisible: false,
      dialogTitle: ''
      // handleType: ''
    };
  },
  created() {},
  mounted() {
    this.getdictList();
    this.getModelList();
  },
  methods: {
    async getdictList() {
      let res = await searchFaultLocation(); // 故障部位
      this.columnsR1.find(item => item.dataIndex === 'faultPositionCode').editItems = res.data.map(x => ({ text: x.faultLocationName, value: x.faultLocationCode }));
      let res1 = await searchFaultType(); // 缺陷类型
      this.columnsR1.find(item => item.dataIndex === 'defectClassCode').editItems = res1.data.map(x => ({ text: x.defectTypeName, value: x.defectTypeCode }));
    },
    async getModelList() {
      let res = await findProjectModelList({ WXXMDY: 'WXXMDY' }); // 车系;
      this.columnsR1.find(item => item.dataIndex === 'series').editItems = res.data.map(x => ({ text: x.MODEL_LABOUR_NAME, value: x.SERIES_ID + '', index: x.index }));
    },
    createFrom() {
      return [
        {
          type: 'INPUT',
          label: '经销商',
          fieldName: 'distributor',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '反馈单号',
          fieldName: 'feedbackNo'
        },
        {
          type: 'SELECT',
          label: '单据状态',
          fieldName: 'documentStatus',
          itemList: this.createDictList('8072')
        },
        {
          type: 'RANGE_DATE',
          label: '提交日期',
          fieldName: 'commitDate'
        },
        {
          type: 'RANGE_DATE',
          label: '操作日期',
          fieldName: 'operationDate'
        },

        {
          type: 'INPUT',
          label: 'VIN',
          fieldName: 'vin',
          rules: [{ pattern: /^(\w){17,17}$/, message: '请输入正确的VIN', trigger: 'blur' }]
        }
      ];
    },
    createTableColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          fixed: 'left',
          align: 'center',
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          // width: 150,
          fixed: 'left',
          align: 'center',
          render: props => {
            return (
              <div>
                <el-button size="mini" type="text" onClick={() => this.editHandle(props.row)}>
                  编辑
                </el-button>
                <el-button size="mini" type="text" onClick={() => this.delLabour(props.row)}>
                  删除
                </el-button>
              </div>
            );
          }
        },
        {
          title: '经销商代码',
          width: 150,
          showOverflowTooltip: true,
          dataIndex: 'dealerCode',
          sorter: true,
          filter: true
        },
        {
          title: '经销商简称',
          dataIndex: 'dealerAbbreviation',
          sorter: true,
          filter: true
        },
        {
          title: '单据类型',
          dataIndex: 'billTypeCode',
          sorter: true,
          filter: true,
          render: props => {
            return <span>{this.createDictText(props.row.billTypeCode, '8210')}</span>;
          }
        },
        {
          title: '反馈单号',
          dataIndex: 'feedbackNo',
          sorter: true,
          filter: true
        },
        {
          title: '单据状态',
          dataIndex: 'status',
          sorter: true,
          filter: true
          // hidden: true
        },
        {
          title: '操作日期',
          dataIndex: 'operationDate',
          showOverflowTooltip: true,
          sorter: true,
          filter: true,
          dateFormat: 'yyyy-MM-dd'
          // render: props => {
          //   const pyt = pinyin(props.row.labourName, { style: 4 })
          //     .join('')
          //     .toUpperCase();
          //   return <span>{pyt}</span>;
          // }
        },
        {
          title: '提交日期',
          dataIndex: 'commitDate',
          sorter: true,
          filter: true,
          dateFormat: 'yyyy-MM-dd'
          // render: props => {
          //   return <span>{this.createDictText(props.row.isCommonIdentity, '1004')}</span>;
          // }
        },
        {
          title: '委托书号',
          dataIndex: 'authorizedBookNumber',
          sorter: true,
          filter: true
        },
        {
          title: 'VIN码',
          dataIndex: 'vin',
          width: 150,
          sorter: true,
          filter: true
        },
        {
          title: '车辆用途',
          dataIndex: 'vehicleUse',
          sorter: true,
          filter: true
        },
        {
          title: '客户名称',
          dataIndex: 'customerName',
          sorter: true,
          filter: true
          // editType: 'input',
          // editable: true
        },
        {
          title: '行驶里程',
          dataIndex: 'inMileage',
          sorter: true,
          editable: true
          // render: props => {
          //   return <span>{this.createDictText(props.row.isSpecial, '1004')}</span>;
          // }
        },
        {
          title: '车系',
          dataIndex: 'series',
          sorter: true,
          editable: true,
          // editable: false,
          editType: 'select',
          editItems: []
        },
        {
          title: '销售车型',
          dataIndex: 'salesVehicle',
          sorter: true,
          filter: true,
          editType: 'input',
          editable: true
          // render: props => {
          //   return <span>{this.createDictText(props.row.workerTypeCode, '8041')}</span>;
          // }
        },
        {
          title: '发动机号',
          dataIndex: 'engineNo',
          sorter: true,
          filter: true,
          filterType: 'select'
          // itemList: []
          // render: props => {
          //   return <span>{this.createDictText(props.row.isValid, '1004')}</span>;
          // }
        },
        {
          title: '生产日期',
          dataIndex: 'product',
          sorter: true,
          filter: true,
          dateFormat: 'yyyy-MM-dd'
        },
        {
          title: '销售日期',
          dataIndex: 'saleDate',
          sorter: true,
          filter: true,
          dateFormat: 'yyyy-MM-dd'
        },
        {
          title: '事故车标识',
          dataIndex: 'accidentFlag',
          sorter: true,
          filter: true,
          align: 'center',
          editType: 'input',
          render: props => {
            if (props.row.accidentFlag == 10041001) return <i class="el-icon-check"></i>;
            else return <i class="el-icon-close"></i>;
          }
        },
        {
          title: '非原厂件标识',
          dataIndex: 'originalFlag',
          sorter: true,
          filter: true,
          align: 'center',
          editType: 'input',
          render: props => {
            if (props.row.originalFlag == 10041001) return <i class="el-icon-check"></i>;
            else return <i class="el-icon-close"></i>;
          }
        },
        {
          title: '车辆加装附件情况',
          dataIndex: 'addSituation',
          sorter: true,
          filter: true
        },
        {
          title: '抱怨来源',
          dataIndex: 'complainCode',
          sorter: true,
          filter: true,
          render: props => {
            return <span>{this.createDictText(props.row.complainCode, '5146')}</span>;
          }
        },
        {
          title: '故障从何时开始',
          dataIndex: 'faultBeginTime',
          sorter: true,
          filter: true
        },
        {
          title: '故障频率',
          dataIndex: 'faultFrequencyCode',
          sorter: true,
          filter: true,
          render: props => {
            return <span>{this.createDictText(props.row.faultFrequencyCode, '9724')}</span>;
          }
        },
        {
          title: '是否抛锚',
          dataIndex: 'anchorFlag',
          sorter: true,
          filter: true,
          align: 'center',
          render: props => {
            return <span>{this.createDictText(props.row.anchorFlag, '1004')}</span>;
          }
        },
        {
          title: '故障部位',
          dataIndex: 'faultPositionCode',
          sorter: true,
          filter: true,
          editType: 'select',
          editItems: []
        },
        // {
        //   title: '故障部位代码',
        //   dataIndex: 'faultPositionCode',
        //   sorter: true,
        //   filter: true
        // },
        // {
        //   title: '故障部位名称',
        //   dataIndex: 'faultPositionName',
        //   sorter: true,
        //   filter: true
        // },
        {
          title: '缺陷类型',
          dataIndex: 'defectClassCode',
          sorter: true,
          filter: true,
          editType: 'select',
          editItems: []
        },
        // {
        //   title: '缺陷类型代码',
        //   dataIndex: 'defectClassCode',
        //   sorter: true,
        //   filter: true
        // },
        // {
        //   title: '缺陷类型名称',
        //   dataIndex: 'defectClassName',
        //   sorter: true,
        //   filter: true
        // },
        {
          title: '客户描述',
          dataIndex: 'customerDesc',
          width: 150,
          showOverflowTooltip: true,
          sorter: true,
          filter: true
        },
        {
          title: '故障描述',
          dataIndex: 'faultDesc',
          width: 150,
          showOverflowTooltip: true,
          sorter: true,
          filter: true
        }
      ];
    },

    // selectBreakModal() {
    //   // this.breakShowFlag = true;
    // },
    changetablelist() {},
    changeHandle(val) {
      this.fetchParams = Object.assign({}, val, { xhrAbort: false });
    },
    addHandle() {
      this.type = 'add';
      this.showHandler();
      this.formData['show'] = true;
    },
    editHandle(row) {
      this.type = 'edit';
      this.formData = row;
      this.showHandler();
      this.formData['show'] = true;
    },
    showHandler() {
      this.dialogTitle = `质量反馈单${this.conf[this.type]}`;
      this.feedbackVisible = true;
    },
    // 删除提示框
    delLabour(val) {
      this.$confirm('是否确定删除？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.delRow(val);
        })
        .catch(() => {});
    },
    // 删除
    async delRow(val) {
      console.log(val.PACKAGE_CODE);
      let res = await deleteFeedback(val.id);
      if (res.resultCode === 200) {
        this.$notify.success({ title: '提示信息', message: res.errMsg || '删除成功!' });
        this.fetchParams = { ...this.fetchParams };
      } else {
        this.$notify.error({ title: '提示信息', message: res.errMsg || '删除失败!' });
      }
    },
    changedata() {
      this.fetchParams = { ...this.fetchParams };
      this.feedbackVisible = false;
    },
    downloadTemplate() {},
    importPrice() {},
    relatedItems() {},
    closeHandler(val) {
      this.feedbackVisible = false;
    }
  }
};
</script>
